import React from "react";
import {Popover, Table} from "antd";
import QuestionModel from "../../../model/question";
import PaginationFooter from "../../../component/PaginationFooter/PaginationFooter";
import moment from "moment";
const log = console.log.bind(console)
class Comments extends React.Component {
    constructor(props) {
        super(props)
        this.model = new QuestionModel()
        this.columns = [
            {
                title: 'Uid',
                dataIndex: 'Uid',
            },
            {
                title: '正文',
                dataIndex: 'Txt',
                render: (text) => <Popover trigger='click' content={text}>
                    <a>查看</a>
                </Popover>
            },
            {
                title: '填写时间',
                dataIndex: 'Createt',
                render: (time) => moment(new Date(time * 1000)).format('YYYY-MM-DD HH:mm')
            },
        ]
        this.state = {
            list: [],
            p: 0,
        }
    }

    componentDidMount() {
        this.all()
    }

    all = () => {
        this.model
            .comments({P: this.state.p})
            .then(res => {
                const data = res.data
                if (data.ok) {
                    this.setState({
                        list: data.res,
                    })
                }
            })
    }

    prevPage = () => {
        this.setState({
            p: this.state.p - 1,
        }, () => this.all())
    }

    nextPage = () => {
        this.setState({
            p: this.state.p + 1,
        }, () => this.all())
    }

    render() {
        return (
            <>
                <Table
                    dataSource={this.state.list}
                    columns={this.columns}
                    rowKey={(record, index) => index}
                    pagination={false}
                />
                <PaginationFooter
                    pageIndex={this.state.p}
                    prevPage={this.prevPage}
                    nextPage={this.nextPage}
                />
            </>
        )
    }
}

export default Comments